package pw.mcdarc.mc.bython.Command;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import pw.mcdarc.mc.bython.Bython;

import java.io.File;

/*
This file is part of Bython.
Dont remove this header anytime.
Under the Apache2 License.
You can't sell it, repost it, share it without permission.
Date: 八月,27,2016
*/

public class CommandExecutor implements org.bukkit.command.CommandExecutor{

    private final Bython plugin;

    public CommandExecutor(Bython plugin) {
        this.plugin = plugin;
    }

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (label.equalsIgnoreCase("bython")) {
            if (sender instanceof  Player && !sender.isOp()) {
                return false;
            }
            switch (args.length) {
                case 0:
                    if (sender instanceof Player | sender instanceof ConsoleCommandSender) {
                        String[] s = new String[]{"§b❤=========§9Bython§b========❤", String.format("§5已载入脚本: %s", Bython.LoadedFiles.size()), String.format("§6已注册事件脚本: %s", Bython.Events.size()), "§b====================="};
                        sender.sendMessage(s);
                    }
                    return true;
                case 2:
                    if (args[0].equalsIgnoreCase("unload")) {
                        Bython.LoadedFiles.remove(new File(Bython.dataFolder + args[1]));
                    }
                    return true;
                case 1:
                    ;
                    return true;
                default:
                    return false;
            }
        }
        return false;
    }
}
